﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NENAData.Factory;
using NENAData.LINQ;

namespace NENAData.Payments
{
    public class NENAPayments
    {

        public enum PaidBy
        {
            PayPal = 0,
            Cheque = 1
        }

        private static MembershipDataContext GetMembershipDB()
        {
            var x = new SQLMembership();
            return x.GetMembershipDB();
        }

        public TransactionPayment GetTransactionPayment(int intTransactionPaymentID)
        {

            MembershipDataContext db = GetMembershipDB();

            var oTP = (from transactionPayment in db.TransactionPayments 
                       join affiliate in db.Affiliates on transactionPayment.PaymentTo equals affiliate.Affiliate_ID
                       where transactionPayment.TransactionPaymentID == intTransactionPaymentID &&
                             transactionPayment.TransactionCompleted
                       select transactionPayment).FirstOrDefault();

            return oTP;
        }

        public TransactionPayment GetTransactionPayment(int intTransactionID_NENA, int intMemberID)
        {

            MembershipDataContext db = GetMembershipDB();
            //Convert.ToInt32(

            var oTP = (from transactionPayment in db.TransactionPayments
                       join affiliate in db.Affiliates on transactionPayment.PaymentTo equals affiliate.Affiliate_ID
                       where transactionPayment.Member_ID == intMemberID &&
                             transactionPayment.TransactionID_NENA == intTransactionID_NENA &&
                             transactionPayment.TransactionCompleted
                       select transactionPayment).FirstOrDefault();

            return oTP;
        }
        public List<TransactionPayment> GetTransactionPayments(int intTransactionID_NENA, int intMemberID)
        {

            MembershipDataContext db = GetMembershipDB();
            //Convert.ToInt32(

            var oTP = (from transactionPayment in db.TransactionPayments
                       join affiliate in db.Affiliates on transactionPayment.PaymentTo equals affiliate.Affiliate_ID
                       where transactionPayment.Member_ID == intMemberID &&
                             transactionPayment.TransactionID_NENA == intTransactionID_NENA &&
                             transactionPayment.TransactionCompleted
                       select transactionPayment);

            return oTP.ToList();
        }
        //todo: figure out how to do complex types
        //public TransactionPayment GetTransactionPayment(int intTransactionID, int intMemberID)
        //{

        //    MembershipDataContext db = GetMembershipDB();

        //    var oTransaction = (from m in db.Members
        //                        join transactionPayment in db.TransactionPayments on m.Member_ID equals
        //                            transactionPayment.Member_ID
        //                        join transaction in db.Transactions on transactionPayment.TransactionID_NENA equals
        //                            transaction.TransactionID_NENA
        //                        join affiliate in db.Affiliates on transactionPayment.PaymentTo equals
        //                            affiliate.Affiliate_ID
        //                        where m.Member_ID == intMemberID &&
        //                              transactionPayment.TransactionPaymentID == intTransactionID &&
        //                              transactionPayment.TransactionCompleted
        //                        select new
        //                        {
        //                            m,
        //                            transactionPayment,
        //                            transaction,
        //                            affiliate
        //                        }).Single();

        //    return oTransaction;
        //}
    }
}